﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AjaxControlToolkit;
using System.Text;
using System.Net;

namespace HTTPDebuggerTools.com
{
    public partial class ViewBrowserHeaders : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            NoBotState state;
            if (!NoBot1.IsValid(out state))
                Response.Redirect("http://www.httpdebugger.com/");

            ShowHeaders();
        }

        void ShowHeaders()
        {
            try
            {
                StringBuilder sbRequest = new StringBuilder();

                sbRequest.Append("<div class='nooverflow'>");
                sbRequest.AppendFormat("<strong>IP Address: {0}</strong><br /><br />", Request.UserHostAddress);
                AppendTable(sbRequest);
                sbRequest.Append("</div>");

                RequestHeaders.Text = sbRequest.ToString();
            }
            catch
            {
            }
        }

        void AppendTable(StringBuilder sb)
        {
            sb.Append("<table>");

            for (int i = 0; i < Request.Headers.Count; i++)
            {
                string name = Request.Headers.GetKey(i);
                string val = Request.Headers.Get(i);

                sb.Append("<tr>");

                bool alt = (i % 2 == 0);

                sb.Append(alt ? "<th class='header_td1'>" : "<th class='header_td2'>");
                sb.Append(name);
                sb.Append("</th>");

                sb.Append(alt ? "<td class='header_td1'>" : "<td class='header_td2'>");
                sb.Append(val);
                sb.Append("</td>");

                sb.Append("</tr>");
            }

            sb.Append("</table>");
            sb.Append("<br />");
        }
    }
}
